package serialComm;

import java.io.IOException;

public class GetNewMessageRunnable extends SerialSms{
	protected synchronized void getNewMessage() throws IOException, InterruptedException {
		try {
			
			System.out.println("Inside GetNewMessageRunnable Class :");
			
			sendCommand("AT+CMGL=\"REC UNREAD\"");
			boolean checkState = false;
			checkState = parseMsg("OK");
			if(checkState) {
				System.out.println("Content Found ");
			}
			else
			{
				System.out.println("Content Not Found.");
				Thread.sleep(SHORTDELAY);
			}
		} catch(IOException e) {
			System.out.print("IOException caught : " + e.toString());
		} catch(InterruptedException e) {
			System.out.print("InterruptedException caught : " + e.toString());
		}
		finally {
			Thread.sleep(LONGDELAY);
		}		
		
	}
	public void run() {
		try {
			getNewMessage();
		} catch (IOException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		} catch (InterruptedException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}finally {
			System.out.println("Existing ...");
		}
		
	}
}
